package com.yfqy.app.security.login.jscode;

import com.yfqy.app.security.login.LoginUserInfo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;

@Setter
@Getter
public class JSCodeAuthentication extends AbstractAuthenticationToken {

    /**
     * 注册来源ID
     */
    private Long regFromId;

    private String phone;

    /**
     * 小程序的jscode
     */
    private String js_code;
    private String grant_type = "authorization_code";

    private LoginUserInfo currentUser;

    public JSCodeAuthentication() {
        super(null);
    }

    public JSCodeAuthentication(LoginUserInfo loginUserInfo) {
        super(loginUserInfo.getAuthorities());
        this.currentUser = loginUserInfo;
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return isAuthenticated() ? currentUser : js_code;
    }
}
